<template>
    <view class="bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="background-color: white; text-align: center; width: 1000px; overflow: auto;">
                <div class="tr">
                    <div class="td text-center bold" style="width: 100px;">
                        <div style="width: 100px;">推荐商品</div>
                    </div>
                    <div class="td text-center bold" style="width: 200px;">商品标题</div>
                    <div class="td text-center bold" style="width: 200px;">开始时间</div>
                    <div class="td text-center bold" style="width: 200px;">结束时间</div>
                    <div class="td text-center bold" style="width: 100px;">状态</div>
                    <div class="td text-center bold" style="width: 100px;">显示顺序</div>
                    <div class="td text-center bold" style="width: 100px;">操作</div>
                </div>

                <div class="tr" v-for="(item, index) in tbGoodsRecommendList" :key="item.id">
                    <div class="td" style="width: 100px;" @click="navigateTo(`/pages/common/goods-detail/index?id=${item.goodsId}`)">
                        <image style="height: 100px; width: 100px; padding-top: 4px;"
                               :src="item.thumbnailUrl ? item.thumbnailUrl + '?imageView2/1/w/300/h/300' : '/static/default-image/goods.jpg'"
                               mode="aspectFill"></image>
                    </div>
                    <div class="td" style="width: 200px;" @click="navigateTo(`/pages/common/goods-detail/index?id=${item.goodsId}`)">
                        {{item.goodsTitle | toEmptyStr}}
                    </div>
                    <div class="td" style="width: 200px;">{{item.startTime}}</div>
                    <div class="td" style="width: 200px;">{{item.endTime}}</div>
                    <div class="td" style="width: 100px;">{{item.statusText}}</div>
                    <div class="td" style="width: 100px;">{{item.displayOrder}}</div>
                    <div class="td" style="width: 100px;">
                        <div style="margin-top: 10px; text-decoration: underline;"
                             @click="navigateTo('/pages/common/goods-recommend/goods-recommend-edit/index', null, item)">
                            编辑
                        </div>
                        <div style="margin-top: 10px; text-decoration: underline;" @click="deleteTbGoodsRecommendById(item, index)">
                            删除
                        </div>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbGoodsRecommendList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="padding-bottom: 5px;"></div>

        <u-button @click="navigateTo(`/pages/common/goods-recommend/goods-recommend-add/index?fkId=${fkId}`, null, findTbGoodsRecommendList)">
            添加推荐商品
        </u-button>
    </view>
</template>

<script>

    import myImg from '@/components/my-img'
    import {CommonUtil} from "../../../dev/core/utils/common.util";
    import {TbGoodsRecommendService} from "../../../dev/services/tb-goods-recommend.service";

    export default {
        props: ["fkId"],
        data() {
            return {
                tbGoodsRecommendList: []
            }
        },
        components: {
            myImg,
        },
        mounted() {
            const _self = this;
            _self.findTbGoodsRecommendList();
        },
        methods: {
            findTbGoodsRecommendList() {
                const _self = this;
                new TbGoodsRecommendService().findTbGoodsRecommendListCascade({
                    fkId: _self.fkId
                }).then(result => {
                    _self.tbGoodsRecommendList = [];
                    _self.$nextTick(() => {
                        _self.tbGoodsRecommendList = result;
                    });
                    _self.$forceUpdate();
                });
            },
            /**
             * 删除推荐商品
             * @param item
             */
            deleteTbGoodsRecommendById(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbGoodsRecommendService().deleteTbGoodsRecommendById(item.id).then(data => {
                                _self.tbGoodsRecommendList.splice(index, 1);
                            });
                        }
                    }
                });
            },
        }
    }
</script>

<style lang="scss" scoped>
</style>
